//
//  ContactViewTableView.m
//  YZZX
//
//  Created by Easaa on 15/5/5.
//  Copyright (c) 2015年 Easaa. All rights reserved.
//

#import "ContactViewTableView.h"

#import "ContactTableViewCell.h"



@implementation ContactViewTableView
{
    HXHttpRequest       *_httpRequest;
    NSMutableArray      *ContactData;

}

- (id)initWithFram:(CGRect)frame;// ObjectID:(NSDictionary *)objectDic
{
    self = [super initWithFrame:frame];
    if (self)
    {
        
        ContactData = [[NSMutableArray alloc]init];
        [self RequstDataListTableview];
        self.delegate = self;
        self.dataSource =self;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;  //去掉分割线
        self.allowsSelection=NO;  //取消选中效果
        
        
        
        
        // 添加传统的下拉刷新
        __weak typeof(self) weakSelf = self;
        // 设置回调（一旦进入刷新状态就会调用这个refreshingBlock）
        [self addLegendHeaderWithRefreshingBlock:^{
            
            [weakSelf RequstDataListTableview];
            
            
        }];
        

        
    }
    
    return self;

}




-(void)RequstDataListTableview
{
    //列表请求
    NSDictionary* dicParams = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [XSZ_UICommon useridChangUaerdfLoginBoolString],                @"user_id",
                                        @"1",                @"site_id",nil];
    
    if (_httpRequest == nil)
    {
        _httpRequest = [[HXHttpRequest alloc] init];
        _httpRequest.delegate = self;
        
        
        
    }
    [_httpRequest requestForParams:dicParams andMethod:YZ_SERICER_LIST andTag:1023];//@"system.time"];//
    
}




#pragma mark - HXHttpRequestDelegate  代理

- (void)requestFinished:(NSString *)responseString andStatusCode:(int)statusCode andTag:(NSInteger)tag
{
    
    
    // 停止刷新状态
    [self.legendHeader endRefreshing];
      
        NSDictionary *dic = [[NSDictionary alloc]init];
        dic = [JsonUtil jsonToDic:responseString];
        
        if ([dic[@"data"] isEqual:[NSNull null]])
        {
            return;
        }
        
        NSString * strs = dic[@"data"];
        
        NSDictionary *dics =[JsonUtil jsonToDic:strs];
        
        NSArray *arryy =(NSArray *)dics;
        
        //NSLog(@"-----------> %@",arryy);

    
    
        [ContactData removeAllObjects];
    
        for (NSDictionary *dicuu in arryy)
        {
            ContactViewDataModel  *modeContact =[[ContactViewDataModel alloc]initWithDataContact:dicuu];
            [ContactData addObject:modeContact];
        }
        
        
        [self reloadData];
    
      
}


#pragma mark  HXHttpRequest - 请求代理，，错误代理
- (void)requestFailed:(NSError *)error andTag:(NSInteger)tag
{
    

    
}




#pragma arguments - mark  UITableViewDelegate
// 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    
    return ContactData.count;
}


//设置每行高度（每行高度可以不一样）
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    return 190;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static  NSString  *CellIdentiferId = @"ContactlitID";
    ContactTableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentiferId];

    if (cell == nil) {
        NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"ContactTableViewCell" owner:nil options:nil];
        cell = [nibs lastObject];
       // cell.backgroundColor = [UIColor clearColor];
        
        
    }
    
    if(ContactData.count<1)
    {
        return cell;
    }
    ContactViewDataModel *cellmodel = [ContactData objectAtIndex:indexPath.row];
    
    [cell.HeadPortraitImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.hellomommy.cn%@",cellmodel.Photo]] placeholderImage:[UIImage imageNamed:@"bg"]];
    [cell.NameLable setText:cellmodel.Name];
    [cell.SiteNameLable setText:cellmodel.HeadShip];
    [cell.DescriptionLable setText:cellmodel.Description];
    
    
    cell.Mobile = cellmodel.Mobile;
    cell.SiteId = cellmodel.SiteId;
    cell.UserId = cellmodel.UserId;
    cell.id_massge = cellmodel.id_biaoshi;

    
      
    return cell;
}


//响应点击事件

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
//    
//    if(indexPath.row<ArryDataCategory.count)
//    {
//        [self.Leftdelegate ChangMainViewContorllerDataAndUIModelTag:indexPath.row];
//    }
    
    
}






@end
